﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class readview : System.Web.UI.Page
{
    public string Classn;
	public string toptitle,topcontent,addtime;
	string search_id = "";
    protected void Page_Load(object sender, EventArgs e)
    {
            if (Request.QueryString["id"] != null) { search_id = Request.QueryString["id"].ToString(); }
            if (IsNumeric(search_id) == false) { search_id = "1"; }

            if (search_id != "" )
            {
				ShowData();
				
				Socut.Reader sdr = new Socut.Reader("select * from web_notice where id=" +search_id);

					sdr.Read();
					int cid=Int32.Parse(sdr["smallclassid"].ToString());
        
					sdr.Close();

					switch(cid)
					{
					case 3:
					Classn="工作动态";
					break;
					case 8:
					Classn="诉讼指南";
					break;
					case 9:
					Classn="诉讼文档格式下载";
					break;
					default:
					Classn="工作动态";
					break;
					}
            }

		
		//新闻内容
    
    }
	
	private void ShowData()
	{
		Socut.Reader sqlDataReader = new Socut.Reader("select * from web_notice where id=" +search_id);
        try
        {
			sqlDataReader.Read();
			toptitle=sqlDataReader["title"].ToString();
			topcontent=htmlstr(sqlDataReader["content"].ToString());
			addtime=sqlDataReader["addtime"].ToString();
        }
        catch {
            Response.Write("为保证网站的服务质量，服务器临时维护中...请稍候!");
            Response.End();
        }
        
		sqlDataReader.Close();

	}


    public string htmlstr(string chr)
    {
        if (chr == null)
            return "";
        //chr = chr.Replace("<", "&lt");
        //chr = chr.Replace(">", "&gt");
        chr = chr.Replace("\n", "<br>");
        //chr = chr.Replace("\"", "&quot;");
        //chr = chr.Replace("'", "&#39;");
        //chr = chr.Replace(" ", "&nbsp;");
        chr = chr.Replace("select", "");
        chr = chr.Replace("delete", "");
        chr = chr.Replace("update", "");
        chr = chr.Replace("drop", "");
        //chr = chr.Replace(";", "");
        //chr = chr.Replace("(", "");
        //chr = chr.Replace(")", "");
        chr = chr.Replace("and", "");
        chr = chr.Replace("or", "");
        //chr = chr.Replace("\r", "");
        return (chr);
    }

    static bool IsNumeric(string str)
    {
        if (str == null || str.Length == 0)
            return false;
        foreach (char c in str)
        {
            if (!Char.IsNumber(c))
            {
                return false;
            }
        }
        return true;
    }
    protected void lktitle_Click(object sender, EventArgs e)
    {
        if (ViewState["sort"].ToString().Contains("asc"))
        {

            ViewState["sort"] = " order by Title desc";
        }
        else
        {
            ViewState["sort"] = " order by Title asc";
        }
    
        ShowData();
    }
    protected void lkdate_Click(object sender, EventArgs e)
    {
        if (ViewState["sort"].ToString().Contains("asc"))
        {

            ViewState["sort"] = " order by addtime desc";
        }
        else
        {
            ViewState["sort"] = " order by addtime asc";
        }
       
        ShowData();
    }
}
